<template>
  <div class="personalCenter-container">
    <!-- 标题 start -->
    <el-card style="margin-bottom: 10px">
      <div
        style="display: flex;flex-direction: row;justify-content: space-between"
      >
        <div>
          <div class="verticalBar"></div>
          <span style="color: #1074fd">使用教程</span>
        </div>
        <div>
          <span style="color: #999999;font-size: 12px">数据每日00:00更新</span>
        </div>
      </div>
    </el-card>
    <div style="margin-top: 20px">
      <div :class="this.tabPosition ? 'selectItem' : 'videoItem'" @click="changeVideo">文档教程</div>
      <div :class="this.tabPosition ? 'videoItem' : 'selectItem'" @click="changeVideo">视频教程</div>
    </div>
    <el-card v-if="this.tabPosition" style="position: relative">
      <div>
        <div style="display: flex;justify-content: space-around">
          <el-button type="text" v-for="item in typeList" :key="item.fileType" :class="item.fileType === userOrganCode.fileType ? 'worldTit' : ''"  @click="changeTypeList(item)" >{{item.name}}</el-button>
        </div>
        <div v-for="item in worldGroup" :key="item.id" class="videoGroup" @click="videoGroupDownload(item)">
          <div v-show="item.type === '0'" >
            <img src="@/assets/img/oms/worldBg.png" class="worldGroupItem"/>
          </div>
          <div class="videoGroupTit">{{item.title}}</div>
<!--          <div class="videoGroupTitN">{{item.nextTitle}}</div>-->
        </div>
      </div>
      <div>
      </div>
    </el-card>
    <el-card v-if="!this.tabPosition" style="position: relative">
      <div style="display: flex;justify-content: space-around">
        <el-button type="text" v-for="item in typeList" :key="item.fileType" @click="changeTypeList(item)" :class="item.fileType === userOrganCode.fileType ? 'worldTit' : ''">{{item.name}}</el-button>
      </div>
      <div>
        <div v-for="item in videoGroup" :key="item.id" class="videoGroup" @click="videoGroupDownload(item)">
          <div class="videoGroupItem" v-show="item.type === '1'">
            <img src="@/assets/img/oms/uploadBig.png" class="videoGroupImg"/>
            <div class="videoFoot"></div>
            <div class="videoSize" >{{item.size}}MB</div>
          </div>
          <div class="videoGroupTit">{{item.title}}</div>
<!--          <div class="videoGroupTitN">{{item.nextTitle}}</div>-->
        </div>
      </div>
    </el-card>
  </div>
</template>

<script>
  import API from "@/network/api/omsApi";
  export default {
    name: "index",
    data() {
      return {
        worldGroup: [],
        videoGroup: [],
        videoTotal: 0,
        worldTotal: 0,
        fullscreenLoading: false,
        headers: {
          session_id: ""
        },
        typeList: [
          {
            name: '全部',
            fileType: '10'
          },
          {
            name: '培训和案例',
            fileType: '0'
          },
          {
            name: '云手机操作',
            fileType: '1'
          },
          {
            name: '虚拟机教程',
            fileType: '2'
          },
          {
            name: '注册',
            fileType: '3'
          },
          {
            name: '引流操作',
            fileType: '4'
          },
          {
            name: '直播',
            fileType: '5'
          },
          {
            name: '话术参考',
            fileType: '6'
          },
          {
            name: '各社交app日活',
            fileType: '7'
          },
          {
            name: '辅助工具资料汇总',
            fileType: '8'
          },
          {
            name: '其他',
            fileType: '9'
          }
        ],
        videoValue: {
          size: '',
          url: '',
          type: 1
        },
        worldValue: {
          url: '',
          type: 0
        },
        tabPosition: false,
        dialogFormVisible: false,
        dialogTextVisible: false,
        form: {
          title: '',
          nextTitle: ''
        },
        userOrganCode: {
          organCode: '',
          platformType: '0',
          fileType: '0'
        },
        formLabelWidth: '80px',
        currentUserInfo: ''
      }
    },
    created() {
      this.currentUserInfo = JSON.parse(localStorage.getItem("updateUserInfo"));
      const text = this.currentUserInfo.organCode.split('_')
      console.log(text)
      this.userOrganCode.organCode = text[0] + '_' + text[1]
      this.headers.session_id = this.currentUserInfo.token;
      this.videoList();
    },
    methods: {
      changeTypeList (item) {
        console.log(item)
        this.userOrganCode.fileType = item.fileType
        this.videoList()
      },
      videoGroupDownload (item) {
        window.open(item.url)
      },
      videoList() {
        this.worldGroup = []
        this.videoGroup = []
        API.videoList({
          ...this.userOrganCode
        }).then(res => {
          if (res.data.code === 0) {
            console.log(res.data.data, 'res.data')
            res.data.data.forEach(item => {
              if (item.type === '0') {
                this.worldGroup.push(item)
                this.worldTotal++
              } else {
                this.videoGroup.push(item)
                this.videoTotal++
              }
            })
          } else {
            this.$message.warning(res.data.msg);
          }
        })
      },
      changeVideo() {
        this.tabPosition = !this.tabPosition
      },
      openVideo() {
        this.dialogFormVisible  = true
        this.form.nextTitle = ''
        this.form.title = ''
        this.videoValue.url = ''
      },
      openWorld() {
        this.dialogTextVisible  = true
        this.form.nextTitle = ''
        this.form.title = ''
        this.worldValue.url = ''
      },
      beforeAvatarUpload(file) {
        this.fullscreenLoading = true;
        this.videoValue.size = parseFloat(file.size / 1024 / 1024).toFixed(2) //获取文件大小
      },
      docUploadSuccessWorld(res) {
        if (res.code === 0) {
          this.$message.success("文档上传成功");
          this.worldValue.url = res.data;
        } else {
          this.$message.warning(res.msg);
        }
      },
      docUploadSuccess(res) {
        console.log(res.data)
        if (res.code === 0) {
          this.$message.success("上传成功");
          this.fullscreenLoading = false;
          this.videoValue.url = res.data;
        } else {
          this.$message.warning(res.msg);
        }
      },
      onSubmit() {
        API.uploadVideo({
          ...this.form,
          ...this.videoValue,
          ...this.userOrganCode
        }).then(res => {
          if (res.code === 0) {
            this.$message.success("提交成功");
            this.fullscreenLoading = false;
            this.dialogFormVisible = false;
          } else {
            this.$message.warning(res.msg);
          }
        })
      },
      onSubmitWorld() {
        API.uploadVideo({
          ...this.form,
          ...this.worldValue,
          ...this.userOrganCode
        }).then(res => {
          if (res.code === 0) {
            this.$message.success("提交成功");
            this.dialogTextVisible = false;
          } else {
            this.$message.warning(res.msg);
          }
        })
      }

    }
  }
</script>

<style scoped>
  /deep/ #updBox .el-upload-list__item-name {
    margin-top: 3px;
  }

  /deep/ #updBox .el-upload-list__item:first-child {
    margin-top: -34px;
  }

  /deep/ #updBox .el-upload-list {
    padding: 0 10px;
  }
  .videoGroup {
    display: inline-block;
    margin-top: 20px;
    margin-right: 40px;
  }
  .videoGroupTit {
    color: #666666;
    font-family: Microsoft YaHei;
    font-weight: bold;
    font-size: 14px;
    line-height: normal;
    margin-top: 4px;
  }
  .videoGroupTitN {
    color: #9B9B9B;
    font-family: Microsoft YaHei;
    font-weight: bold;
    font-size: 10px;
    line-height: normal;
    letter-spacing: 0px;
    text-align: left;
  }
  .videoGroupItem {
    border-radius: 4px;
    background: #222222;
    width: 100px;
    height: 100px;
    display: inline-block !important;
    position: relative;
  }
  .worldGroupItem {
    border-radius: 4px;
    width: 100px;
    height: 100px;
    display: inline-block !important;
    position: relative;
  }
  .videoGroupImg {
    width: 30px;
    height: 30px;
    margin: 34px 0 0 34px;
  }
  .videoSize {
    color: white;
    font-size: 10px;
    line-height: 10px;
    position: absolute;
    bottom: 8px;
    right: 8px;
  }
  .videoTime {
    color: white;
    font-size: 10px;
    line-height: 10px;
    position: absolute;
    bottom: 8px;
    left: 8px;
  }
  .videoFoot {
    opacity: 0.10000000149011612;
    border-radius: 0px 0px 0px 0px;
    background: #FFFFFF;
    width: 128px;
    height: 26px;
    position: absolute;
    bottom: 0;
  }
  .videoImg {
    width: 30px;
    height: 30px;
    margin-top: 48px;
  }
  .videoSuccess {
    border-radius: 4px;
    background: #222222;
    width: 128px;
    height: 128px;
    position: relative;
  }
  .uploadIcon {
    border-radius: 4px;
    background: #F2F2F2;
    width: 100px;
    height: 100px;
    margin-top: 20px;
  }
  .uploadIcon1 {
    border-radius: 4px;
    background: #F2F2F2;
    width: 100px;
    height: 100px;
  }
  .uploadText {
    color: #666666;
    font-family: Microsoft YaHei;
    font-weight: bold;
    font-size: 14px;
    line-height: normal;
    margin-left: 5px;
  }
  .buttonDel {
    border-radius: 4px;
    background: #FF7A00;
    color: #ffffff;
    position: absolute;
    right: 36px;
    top: 25px;
  }
  .worldTit {
    color: #1074FD;
    font-family: Source Han Sans CN;
    font-weight: bold;
    font-size: 16px;
    line-height: 22px;
  }
  .worldText {
    color: #9B9B9B;
    font-family: Source Han Sans CN;
    font-weight: bold;
    font-size: 12px;
    line-height: 12px;
    margin-top: 9px;
  }
  .verticalBar {
    width: 3px;
    height: 18px;
    background: #1074fd;
    display: inline-block;
    vertical-align: top;
    margin-right: 10px;
    margin-top: 2px;
  }
  .videoItem {
    color: #464646;
    font-family: Microsoft YaHei;
    font-weight: bold;
    font-size: 18px;
    line-height: 42px;
    width: 102px;
    height: 44px;
    background: #DCDCDC;
    display: inline-block;
    text-align: center
  }
  .selectItem {
    color: #ffffff;
    font-family: Microsoft YaHei;
    font-weight: bold;
    font-size: 18px;
    line-height: 42px;
    width: 102px;
    height: 44px;
    background: #1074FD;
    display: inline-block;
    text-align: center
  }
</style>
